﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FisheryPlatform.Entity;
using FisheryPlatform.Bussiness.Product;
using FisheryPlatform.Bussiness.Account;
using FisheryPlatform.Bussiness.LoginCookie;
using FisheryPlatform.Bussiness.FileStore;
using FisheryPlatform.SiteConfig.FileStore;
using FisheryPlatform.Common;

namespace FisheryPlatform.Web.WWW.Product
{
    public partial class Details : System.Web.UI.Page
    {
        protected ProductEntity productInfo = null;
        protected string ContactInfoImageUrl = "";
        protected string RealName = "";

        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected override void OnPreRender(EventArgs e)
        {
            #region
            base.OnPreRender(e);

            long proId = 0;
            if (long.TryParse(Request.QueryString["proCode"], out proId))
            {
                productInfo = ProductManager.Get(proId);
                menuStyle.Title = HttpUtility.HtmlEncode(productInfo.Title);
                if (productInfo.ProductId == 0)
                {
                    Response.End();
                }
            }
            else
            {
                productInfo = new ProductEntity();
                Response.End();
            }

            var adminUserInfo = new LoginUserInfo().AdminUserInfo;
            var phone = "";
            if (productInfo.ShowCustomerInfo == 1)
            {
                RealName = productInfo.Contact;
                phone = productInfo.Mobile + (string.IsNullOrEmpty(productInfo.Phone) ? "" : "," + productInfo.Phone);
            }
            else
            {
                RealName = adminUserInfo.RealName;
                phone = adminUserInfo.Mobile + (string.IsNullOrEmpty(adminUserInfo.Phone) ? "" : "," + adminUserInfo.Phone);
            }
            
            UploadFileEntity uploadFile = new UploadFileEntity(productInfo.ProductId.ToString(), "proid.jpg", ImageUtility.ContactPhone(phone));
            uploadFile.UploadDate = productInfo.CreateDate;//必须得
            ContactInfoImageUploadProvider imageUpload = new ContactInfoImageUploadProvider(uploadFile);
            imageUpload.Save();
            ContactInfoImageUrl = uploadFile.PublishUrl + uploadFile.PublishUrlPath;
            #endregion
        }
    }
}